package com.skivingcloud.report.bigscreen.controller;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.skivingcloud.common.utils.R;
import com.skivingcloud.report.bigscreen.entity.ChartDto;
import com.skivingcloud.report.bigscreen.entity.ReportDashboard;
import com.skivingcloud.report.bigscreen.service.IReportDashboardService;
import com.skivingcloud.report.bigscreen.service.IReportDashboardWidgetService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 报表看板 前端控制器
 * </p>
 *
 * @author skivingcloud
 * @since 2022-07-29
 */
@RestController
@RequestMapping("/bigscreen/reportDashboard")
public class ReportDashboardController {

	private static Logger log = LoggerFactory.getLogger(ReportDashboardController.class);

	@Autowired
	private IReportDashboardService reportDashboardService;
	@Autowired
	private IReportDashboardWidgetService reportDashboardWidgetService;


	/**
	 * 根据编码查询大屏设计
	 * 
	 * @param reportCode
	 * @return
	 * @throws Exception
	 */
	@GetMapping("/getReportDetailDashboard/{reportCode}")
	public R getReportBigscreendetailDashboard(@PathVariable("reportCode") String reportCode) throws Exception {
		ReportDashboard reportDashboard = reportDashboardService.selectById(reportCode);
		return R.ok().put("dashboard", reportDashboard);
	}

	/**
     * 获取去单个图层数据
     * @param dto
     * @return
     */
    @PostMapping("/getChartsData")
    public R getData(@RequestBody ChartDto dto) {
		try {
			return R.ok().put("data", reportDashboardService.getChartData(dto));
		} catch (Exception e) {
			log.error("获取数据失败", e);
			return R.error("获取数据失败");
		}
    }
	
}
